<!-- 
	* 摘要：销售商签约的客户列表
	* 软件名称：闪酿鸿蒙版APP
	* 文件名: myCustomers.vue
	* 版本：1.2.0
 -->
<template>
	<view class="paryorder-content">
		
		<z-paging ref="paging" v-model="dataList" @query="queryList" :fixed="false" :auto="true">
		
			<template  #top style="background-color: #F8F8F8;">
				<view>
					<fui-nav-bar title="我的客户" isFixed isOccupy  @leftClick="pageBack">
						<template #right>
							<view   class="u-p-r-20 u-font-28"  @click="$mRouter.push({route:'/pages/sale/myCustomers/signHistory'})">
								签约记录
							</view>
						</template>
					</fui-nav-bar>
				</view>
			</template>
			<!-- 如果希望其他view跟着页面滚动，可以放在z-paging标签内 -->
			<view class="payorder-container" v-for="(item,index) in dataList" :key="index" >
				<view class="payorder-section">
					<image :src="item.buyerLogoUrl?item.buyerLogoUrl:defaultLogo" mode="" class="section-image" ></image>
					<view class="section-list">
						<view class="section-item">
							<view class="section-item-name">{{item.buyerName}}</view>
							<view class="section-item-count u-m-b-10">
								<text class="u-m-r-20 u-font-24" style="color: #999;">本月订单  {{item.tradeCount}}  </text>
								<text class="u-font-24" style="color: #999;">本月交易品类  {{item.itemsCount}}</text>
							</view>
							<view class="section-item-count">
								本月交易额  
								<text class="u-m-l-20" style="font-weight: 500;color: #ff551a;">￥{{item.totalAmount}}</text>
							</view>
						</view>
					</view>
					<view class="u-flex u-col-center u-row-between u-m-l-20" style="height: 100%;">
						<view class="section-btn-box u-m-r-35" @click="$mRouter.push({ route: '/pages/sale/myCustomers/quotation?BuyerId='+item.buyerId+'&ownerName='+item.buyerName })">
							<image src="/static/owners/price.png" mode="" style="height: 46rpx;width: 43rpx;"></image>
							<text class="btn-text">报价单</text>
						</view>
						<view class="section-btn-box" @click="goStatDetails(item.buyerId)">
							<image src="/static/xiaoshou/contractManger.png" mode="" style="height: 46rpx;width: 43rpx;" ></image>
							<text class="btn-text">订单</text>
						</view>
					</view>
					
				</view>
			</view>
			<template #bottom>
				<view class="u-flex " style="background-color: #fff;">
					<view class="u-flex u-row-center u-p-t-40 u-p-b-40" style="flex:1;border-right: 1px solid #eaeaea;" @click="getQrcode">
						<view style="width: 80rpx; height: 80rpx; border-radius: 50%;background-color: #ffbb1a;" class="u-flex u-row-center u-col-center">
							<view class="iconfont icon-erweima" style="font-size: 36rpx;"></view>
						</view>
						<text class="u-font-28 u-m-l-30" style="text-align: center;font-weight:500;">推广码</text>
					</view>
					<view class="u-flex u-row-center u-p-t-40 u-p-b-40" style="flex:1;" @click="goScanPageFn">
						<view style="width: 80rpx;height: 80rpx; border-radius: 50%;background-color: #ffbb1a;" class="u-flex u-row-center u-col-center">
							<fui-icon name="scan" style="font-size:44rpx;font-weight: bold;"></fui-icon>
						</view>
						<text class="u-font-28 u-m-l-30" style="text-align: center;font-weight: 500;">去签约</text>
					</view>
				</view>
			</template>

		</z-paging>
		<!-- <view class="shop-cart-container"  style="bottom:250rpx"  @click="getQrcode">
			<view class="iconfont icon-erweima" style="font-size: 42rpx;"></view>
			<text class="u-font-10" style="width: 100%;text-align: center;">推广码</text>
		</view>
		<view class="shop-cart-container" @click="goScanPageFn">
			<u-icon name="scan" style="font-size: 50rpx;font-weight: bold;"></u-icon>
			<text class="u-font-10" style="width: 100%;text-align: center;">去签约</text>
		</view> -->
		<!-- 二维码显示 -->
		<fui-modal :show="erweimaShow" width="600" :buttons="[]" :maskClosable="true" @cancel="erweimaShow = false">
			<view class="slot-content">
				<view class="u-text-center u-m-t-20">
					推广码
				</view>
				<img :src="erweima" style="width: 100%;" mode="" />
				<!-- #ifdef APP-PLUS -->
				<view class="u-text-center u-p-t-20 u-p-b-20" style="border-top: 1px solid #eee;" @click="saveLocationFn">
					<fui-icon name="download"></fui-icon>
					<text class="u-m-l-10">点击保存图片</text>
				</view>
				<!-- #endif -->
			</view>
		</fui-modal> 
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//v-model绑定的这个变量不要在分页请求结束中自己赋值！！！
				dataList: [],
				searchText:'',
				erweimaShow:false,
				erweima:'',
			}
		},
		methods: {
			// 获取推广二维码
			async getQrcode() {
				uni.showLoading({
					title:'loading...'
				})
				const res = await this.$newHttp.get('api/v1.2/Shop/GetPersonalPromotionQRCodeImage/personalPromotionQRCodeImage.jpg', { responseType: 'arraybuffer'})
				uni.hideLoading();
				if(res){
					this.erweima = 'data:image/jpeg;base64,'+ uni.arrayBufferToBase64(res);
					this.erweimaShow = true;
				}else{
					this.$u.toast('获取推广码失败！');
				}
			},
			saveLocationFn(){
				let base64 = this.erweima;
				 const bitmap = new plus.nativeObj.Bitmap("test");
				     bitmap.loadBase64Data(base64, function() {
				         const url = "_doc/" + new Date().getTime() + ".png";  // url为时间戳命名方式
				         console.log('saveHeadImgFile', url)
				         bitmap.save(url, {
				             overwrite: true,  // 是否覆盖
				             // quality: 'quality'  // 图片清晰度
				         }, (i) => {
				             uni.saveImageToPhotosAlbum({
				                 filePath: url,
				                 success: function() {
				                     uni.showToast({
				                         title: '图片保存成功',
				                         icon: 'none'
				                     })
				                     bitmap.clear()
				                 }
				             });
				         }, (e) => {
				             uni.showToast({
				                 title: '图片保存失败',
				                 icon: 'none'
				             })
				             bitmap.clear()
				         });
				     }, (e) => {
				         uni.showToast({
				             title: '图片保存失败',
				             icon: 'none'
				         })
				         bitmap.clear()
				}); 
			},
			// 扫码签约
			goScanPageFn(){
				// #ifdef APP-PLUS
					uni.scanCode({
						success:  (res) => {
							// this.$mRouter.push({ route: '/pages/sale/signContract/index?qrcode='+res.result });
							this.$mHelper.delayedJump(`/pages/sale/signContract/index?qrcode=${res.result}`,'push',1000);
						},
						fail:(Error)=>{
							console.log(Error);
							this.$u.toast('识别二维码失败')
						},
						complete:(complete)=>{
							console.log(complete);
						}
					});
				// #endif
				// #ifndef APP-PLUS
					this.$mRouter.push({route:'/pages/sale/signContract/scan'})
				// #endif
			},
			// 前往签约页面
			goSignPageFn(){
				this.$mRouter.push({route:'/pages/sale/myCustomers/signContract'});
				
			},
			// 重新加载列表
			reloadFn(){
				this.$refs.paging.reload();
			},
			// 前往订单页
			goStatDetails(id){
				this.$mRouter.push({
					route: '/pages/sale/saleStat/statDetails?id='+id 
				})
			},
			// 加载客户列表
			async queryList(pageNo, pageSize) {
				//组件加载时会自动触发此方法，因此默认页面加载时会自动触发，无需手动调用
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				//模拟请求服务器获取分页数据，请替换成自己的网络请求
				const params = {
					pageIndex: pageNo,
					pageSize: pageSize,
					// id:this.$store.state.shop.shop.id,
					// IsSeller:true
				}
				if(this.searchText!==''){
					params.keywords = this.searchText;
				}
				uni.showLoading({
					title: 'loading...',
					mask: false
				});
				const res = await this.$newHttp.get('api/SalesReport/GetASummaryOfAllBuyerTransactions', { params: params } );
				uni.hideLoading({
					title: 'loading...'
				})
				if(res.code === 200){
					this.$refs.paging.complete(res.data.list);
				}else{
					this.$refs.paging.complete(false);
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/static/iconfont/iconfont.css';
	/* 注意:父节点需要固定高度，z-paging的height:100%才会生效 */
	.paryorder-content {
		height: 100%;
		
	}
	.payorder-container{
		background-color: #fff;
		box-sizing: border-box;
		padding: 0 30rpx;
		.payorder-header{
			display: flex;
			justify-content: space-between;
		}
		.payorder-section{
			display: flex;
			align-items: center;
			box-sizing: border-box;
			padding: 35rpx 0;
			margin-bottom: 20rpx;
			.section-image{
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
				margin-right: 32rpx;
			}
			.section-list{
				flex: 1;
				margin-left: 20rpx;
				
				.section-item{
					width: 100%;
					.section-item-name{
						font-size: 32rpx;
						font-weight: 500;
						margin-bottom: 10rpx;
					}
					.section-item-count{
						font-size: 24rpx;
						color: #999;
					}
					.section-btn{
						width: 160rpx;
						margin-left: 10rpx;
						height:70rpx;
						border-radius: 35rpx;
						border: 1rpx solid #FFBB1A;
						color: #FFBB1A;
						text-align: center;
						line-height: 70rpx;
					}
					.section-btn-disabled{
						border-color:#999999;
						color: #999999;
					}
				}
			}
			.section-btn-box{
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				>.btn-text{
					font-size: 20rpx;
					margin-top: 10rpx;
				}
			}
		}
		
	}
	.shop-cart-container{
		position: fixed;
		bottom: 100rpx; 
		right: 40rpx; 
		width: 120rpx; 
		height: 120rpx; 
		border-radius: 50%; 
		background-color: #FFBB1A;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-wrap: wrap;
		align-content: center;
		box-shadow: 0px 0px 18px 2px rgba(6,0,1,0.1);
		transition: all 0.5s ease;
		z-index: 999;
	}

</style>
